<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>批次未完工序查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'批次未完工序查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件 -->
      <el-form :inline="true" :model="queryInfo" id="queryZone" ref="queryInfoRef" :label-position="'left'"
        :rules="rules">
        <el-form-item label="计划完成时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="主制工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择" clearable filterable>
            <el-option v-for="item in workcenterList" :key="item.workcenterid" :label="item.workcentername"
              :value="item.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="批次号:" prop='containername'>
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入批次号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="重要程度:">
          <el-input v-model.trim="queryInfo.priority" placeholder="请输入" clearable style="width: 120px;"></el-input>
        </el-form-item>

        <el-form-item label="风险等级:">
          <el-input v-model.trim="queryInfo.risklevel" placeholder="请输入" clearable style="width: 120px;"></el-input>
        </el-form-item>

        <el-form-item label="派工人:">
          <el-autocomplete v-model.trim="queryInfo.dispatcher" placeholder="请输入" :trigger-on-focus="false"
            :fetch-suggestions="searchFullnameAsync" :value-key="'fullname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="报工人:">
          <el-autocomplete v-model.trim="queryInfo.reporter" placeholder="请输入" :trigger-on-focus="false"
            :fetch-suggestions="searchFullnameAsync" :value-key="'fullname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="exportDetail">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 主表格 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="零件号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
        <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="主制工区" prop="fromworkcentername" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="重要程度" prop="priority" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="风险等级" prop="risklevel" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="开始时间" prop="startdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="结束时间" prop="enddate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="未完工序" prop="workflowstepname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="单位工时" prop="durationperunit" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="派工时间" prop="dispatchdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="派工人" prop="dispatchemployeename" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="报工时间" prop="reportdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="报工人" prop="reportemployeename" width="100" show-overflow-tooltip></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,20,50,100]" :page-size="12"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { exportExcelData, getParams, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { getFactoryInfo, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js';
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        thisweek: '',
        queryInfo: {
          factoryid: '',
          factoryname: '',
          selectdate: '',//计划完成时间
          workcenterid: '',//主制工区
          productname: '',//零件号
          containername: '',//批次号
          priority: '',//重要程度
          risklevel: '',//风险等级
          dispatcher: '',//派工人
          reporter: '',//报工人
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        rules: { selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        dataList: [],
        workcenterList: [],
        pickerOptions: { shortcuts: [prevMonth, thisMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback, triggerLength: 2 })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        // 查询用户姓名
        searchFullnameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEmployeeAsync', name: 'fullname', value, callback, triggerLength: 1 });
        },
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) { return this.$message.error('必填项不能为空'); }
            this.loading = true;
            this.loadingText = '数据加载中...';
            const { data: { data, meta, total } } = await axios.post('../handler/report/GZSkipStepReport.ashx?action=getData', {
              type: 'getData',
              ...this.queryInfo
            });
            this.loading = false;
            if (meta.status === 500) { return this.$message.error(meta.msg); }
            this.dataList = data;
            this.total = total;
          })
        },
        // 导出
        exportDetail() {
          const config = {
            url: '../handler/report/GZSkipStepReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo, title: `${this.queryInfo.factoryname}批次未完工序统计报表` }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(pageSize) {
          this.queryInfo.pageSize = pageSize;
          this.getData();
        }
      },
      async mounted() {
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfThisMonth, endOfThisMonth];
        const factoryInfo = await getFactoryInfo({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是' });//查询当前分厂信息
        const { factoryid, factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.queryInfo.factoryid = factoryid;
        document.title = factoryname + '批次未完工序统计报表';
        this.workcenterList = await getWorkcenterList({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是', workcentertype: '是' });
        this.getData();
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>